﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sgr.Licence
{
    /// <summary>
    /// 许可证状态扩展方法
    /// </summary>
    public static class LicenseStatusExtensions
    {
        /// <summary>
        /// 获取许可证状态的描述信息
        /// </summary>
        /// <param name="status">许可证状态</param>
        /// <returns>状态描述</returns>
        public static string GetDescription(this LicenseStatus status)
        {
            return status switch
            {
                LicenseStatus.NotActivated => "软件未激活",
                LicenseStatus.Valid => "许可证有效",
                LicenseStatus.NearExpiration => "许可证即将到期",
                LicenseStatus.Expired => "许可证已过期",
                LicenseStatus.Invalid => "许可证无效",
                LicenseStatus.ExceededLicense => "超出授权使用数量",
                LicenseStatus.TimeTempered => "系统时间被篡改",
                LicenseStatus.HardwareChanged => "硬件信息发生变更",
                _ => "未知状态"
            };
        }

        /// <summary>
        /// 检查许可证状态是否允许软件运行
        /// </summary>
        /// <param name="status">许可证状态</param>
        /// <returns>是否可以运行</returns>
        public static bool CanRun(this LicenseStatus status)
        {
            return status switch
            {
                LicenseStatus.Valid => true,
                LicenseStatus.NearExpiration => true,
                _ => false
            };
        }
    }
}